<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:p="http://primefaces.org/ui"
                template="../templates/ui.xhtml">

    <ui:define name="content">

        <h1 class="title ui-widget-header ui-corner-all">Charts - Live Data</h1>
        <div class="entry">
            <p>This example displays an ongoing election between two candidates. Votes are updated live and displayed on a pie chart.</p>

            <h:form id="form">

                <p:poll interval="3" update="votes" />
                
                <p:pieChart id="votes" value="#{chartBean.livePieModel}" title="Live Chart"
                            legendPosition="nw" style="width:400px;height:300px"/>

            </h:form>

            <h3>Source</h3>
            <p:tabView>
                <p:tab title="liveChart.xhtml">
                    <pre name="code" class="xml">
&lt;h:form id="form"&gt;

    &lt;p:poll interval="3" update="votes" /&gt;

    &lt;p:pieChart id="votes" value="\#{chartBean.livePieModel}" title="Live Chart"
                legendPosition="nw" style="width:400px;height:300px"/&gt;

&lt;/h:form&gt;
                    </pre>
                </p:tab>

                <p:tab title="ChartBean.java">
            <pre name="code" class="java">
package org.primefaces.examples.view;

import java.io.Serializable;

import org.primefaces.model.chart.PieChartModel;

public class ChartBean implements Serializable {

    private PieChartModel livePieModel;

	public ChartBean() {
        createLivePieModel();
	}

    public PieChartModel getLivePieModel() {
        int random1 = (int)(Math.random() * 1000);
		int random2 = (int)(Math.random() * 1000);

		livePieModel.getData().put("Candidate 1", random1);
        livePieModel.getData().put("Candidate 2", random2);

        return livePieModel;
    }

    private void createLivePieModel() {
        livePieModel = new PieChartModel();

        livePieModel.set("Candidate 1", 540);
        livePieModel.set("Candidate 2", 325);
    }
}
            </pre>
                </p:tab>

            </p:tabView>
            


        </div>

    </ui:define>
</ui:composition>
